import { PageContainer } from "@ant-design/pro-layout";
import useCommonTable from "@/hooks/useCommonTable";
import { fetchList, update, add, remove } from "@/api/room";

import {
  ProFormText,
  ProFormTextArea,
} from "@ant-design/pro-form";
import { Button } from "antd";
import {history} from 'umi'

export default () => {
  const columns = [
    {
      title: "课程分类名称",
      dataIndex: "name",
      width: 150,
      search: false,
    },
    {
      title: "课程分类编码",
      dataIndex: "code",
      width: 150,
      search: false,
    },
  ];
  const renderFormItem = () => {
    return (
      <>
        <ProFormText
          label="课程分类名称"
          name="name"
          rules={[{ required: true, message: "请输入课程分类名称" }]}
        />
        <ProFormText
          label="课程分类编码"
          name="code"
          placeholder="请输入课程分类编码"
          rules={[
            {
              required: true,
              message: "请输入课程分类编码",
            },
          ]}
        />
        <ProFormTextArea
          fieldProps={{
            rows: 5,
          }}
          name="remark"
          label="备注"
          placeholder="请输入备注"
        />
      </>
    );
  };
  return (
    <PageContainer>
      {useCommonTable({
        title: "课程分类",
        renderFormItem,
        columns,
        modalWidth: 600,
        fetchList,
        add,
        update,
        remove,
        actionColumnWidth: 200,
        showCheckbox: false,
        insertPosition: 3,
        renderOtherAction: (_, record) => {
          return (
            <Button
              type="primary"
              onClick={() => {
                history.push(`/course/children?id=${record._id}`);
              }}
            >
              课程
            </Button>
          );
        },
      })}
    </PageContainer>
  );
};
